// webpack.config.js
const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
    mode: 'none',
    entry: './src/main.js',
    output: { 
        filename: 'js/bundle.js',
        path: path.join(__dirname, 'dist')
    },
    devServer: {
        contentBase: './public'
    },
    module: {
        rules: [
            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.vue$/,
                use: 'vue-loader'
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        esModule: false
                    }
                }
            },
            {
            	test: /\.js$/,
                use: 'eslint-loader',
                exclude: /node_module/,
                enforce: 'pre'
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({ // 通过模板生成 html
        	template: './public/index.html'
    	}),
    	new webpack.DefinePlugin({
    		BASE_URL: '"./"'
        }),
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin({
            patterns: [
                {
                    from: 'public/*.ico',
                    flatten: true
                }
            ]
        })
    ]
}